package com.bdqn;

import java.lang.reflect.Proxy;

public class IntermediaryJdkProxyFactory {
    public static <T> T create(Object target){
        IntermediaryInvocationHandler handler = new IntermediaryInvocationHandler();
        handler.setTarget(target);
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),handler);
    }

    public static void main(String[] args) {
        Buyer buyer = IntermediaryJdkProxyFactory.create(new RealBuyer());
        String result = buyer.havealook();
        System.out.println(result);
    }
}
